package org.hsieh.tr.explore.logger;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Shell;
import org.hsieh.tr.explore.Activator;

/**
 * 
 * @author xiaowei.ye xiaowei.ye@soyatec.com
 * 
 */
public class LogUtil {

    private static LogUtil instance = null;

    private ILog logger = null;

    private LogUtil() {
	logger = Activator.getDefault().getLog();
    }

    public static LogUtil getInstance() {
	if (instance == null) {
	    instance = new LogUtil();
	}

	return instance;
    }

    public void log(int severity, String message, Throwable exception) {
	logger.log(new Status(severity, Activator.getDefault().getPluginID(),
		Status.OK, message, exception));
    }

    public void logCancel(String message, Throwable exception) {
	logger.log(new Status(Status.CANCEL, Activator.getDefault()
		.getPluginID(), Status.OK, message, exception));
    }

    public void logError(String message, Throwable exception) {
	logger.log(new Status(Status.ERROR, Activator.getDefault()
		.getPluginID(), Status.OK, message, exception));
    }

    public void logInfo(String message, Throwable exception) {
	logger.log(new Status(Status.INFO,
		Activator.getDefault().getPluginID(), Status.OK, message,
		exception));
    }

    public void logOk(String message, Throwable exception) {
	logger.log(new Status(Status.OK, Activator.getDefault().getPluginID(),
		Status.OK, message, exception));
    }

    public void logWarning(String message, Throwable exception) {
	logger.log(new Status(Status.WARNING, Activator.getDefault()
		.getPluginID(), Status.OK, message, exception));
    }

    //
    public void promptError(Shell shell, String message, Throwable exception) {
	ErrorDialog.openError(shell, "Transcation explore", message,
		new Status(Status.ERROR, Activator.getDefault().getPluginID(),
			Status.OK, exception.getMessage(), exception));
    }
}